const commitService = require("../services/commitService");
const { successResponse, errorResponse } = require("../utils/response");

// 获取所有提交记录
exports.getAllCommits = async (ctx) => {
  try {
    const commits = await commitService.getAllCommits();
    ctx.body = successResponse(commits, "获取所有提交记录成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

// 获取单个提交记录通过id
exports.getCommitById = async (ctx) => {
  try {
    const commit = await commitService.getCommitById(ctx.params.id);
    ctx.body = successResponse(commit, "获取提交记录成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

// 创建新的提交记录
exports.createCommit = async (ctx) => {
  try {
    const commit = await commitService.createCommit(ctx.request.body);
    ctx.body = successResponse(commit, "创建提交记录成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

// 删除提交记录
exports.deleteCommit = async (ctx) => {
  try {
    await commitService.deleteCommit(ctx.params.id);
    ctx.body = successResponse(true, "删除提交记录成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};
